﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Web.UI;
using NickLee.Common;
using System.Text;

namespace GPCSC.Web.SYS_ORG
{
    public partial class roleEdit :  PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                this.command.Value = Usual.f_querystringToString("command");
                if (this.command.Value == "View")
                {
                    string postid = Usual.f_querystringToString("CommandArg");
                    f_fristLoad(postid);
                    UIFactory.UIFactory_ReadOnly(this);
                    this.buttontr.Style.Add("display", "none");
                }
                else if (this.command.Value == "Edit")
                {
                    string postid = Usual.f_querystringToString("CommandArg");
                    UIFactory.UIFactory_NotReadOnly(this);
                    f_fristLoad(postid);
                }

            }
        }
        protected void f_fristLoad(string PrimaryKey)
        {
            base.o_uiTable.Clear();
            SqlReadXml org = new SqlReadXml();
            base.o_uiTable.Add("@ROLEID", PrimaryKey);
            base.m_uiDataSet = org.ReaderDataSet("sel_role_one", base.o_uiTable);
            if (base.m_uiDataSet.Tables.Count > 0)
            {
                if (base.m_uiDataSet.Tables[0].Rows.Count > 0)
                {
                    //UIFactory set UI controls value:界面工厂设置界面控件值
                    try
                    {
                        base.o_uiTable = UIFactory.UIFactory_Set(this, base.m_uiDataSet.Tables[0]);

                    }
                    catch
                    {

                    }
                 
                  
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            savepost();

        }
        protected void savepost()
        {
            try
            {
                Hashtable htable = f_getElements(base.o_uiTable);

                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                if (this.command.Value == "new")
                {
                    dtable.databyhtables(htable, "add", "CL_ROLE_S", "", "");
                    this.Response.Write("<script>alert('添加角色成功！');window.location.href='roleList.aspx';</script>");
                }
                else if (this.command.Value == "Edit")
                {
                    dtable.databyhtables(htable, "update", "CL_ROLE_S", "CL_ROLE_SOID", Usual.f_querystringToObj("CommandArg").ToString());
                    this.Response.Write("<script>alert('更新角色成功！');window.location.href='roleList.aspx';</script>");
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }

        
        }
        //dtable.

    


        /// <summary>
        /// UIFactory Get Values:通过UIFactory界面工厂获取值
        /// </summary>
        /// <param name="o_uiTable">Filled Hashtable:返回填充后的哈希表</param>
        public Hashtable f_getElements(Hashtable o_uiTable)
        {
            //UIFactory Get Values as Hashtable:界面工厂获取值，并保存在哈希表
            base.o_uiTable.Clear();
            base.o_uiTable = UIFactory.UIFactory_Get(this);
            if (Usual.f_querystringToObj("CommandArg") != null)
            {
                base.o_uiTable.Add("CL_ROLE_SOID",  Usual.f_convertGuid(Usual.f_querystringToObj("CommandArg")));

            }
            else
            {
                base.o_uiTable.Add("CL_ROLE_SOID",  Guid.NewGuid());
            }
            return base.o_uiTable;
        }
    }
}